package com.qf.controller;

import com.qf.annotation.NoLoginCheck;
import com.qf.entity.User;
import com.qf.entity.param.LoginParam;
import com.qf.service.UserService;
import com.qf.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Collections;

/**
 * @author ljw
 * @version 1.0
 * @Date 2025/1/13 19:47
 */
@RestController
@RequestMapping("/user")
public class LoginController {
    @Resource
    private UserService userService;

    @NoLoginCheck
    @PostMapping("/login")
    public R login(@RequestBody LoginParam loginParam){
        String token=userService.login(loginParam);
        return R.ok(Collections.singletonMap("token",token));
    }
    @GetMapping("/info")
    public R getInfo(String token){
        if(token!=null){
            User user=userService.getInfo(token);
            return R.ok(user);
        }
        return R.fail("获取令牌不存在");
    }
    @PostMapping("/logout")
    public R logout(){
        return R.ok("退出成功");
    }
}
